<template>
  <div class="reportFormPage" v-if="show">
    <div class="report-dom">
      <el-row>
        <el-col :span="5" :offset="19">
          <div class="pageNumBox">
            <span>第</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.page }}&nbsp;</span>
            <span>页，共</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.totalPage }}&nbsp;</span>
            <span>页</span>
          </div>
        </el-col>
      </el-row>
      <div class="topTwoBox">
        <div class="centerName">{{ this.form.baobmc }}</div>
        <div class="codeText">
          <tr v-for="(item, index) in form.baobbhList">{{ item }}</tr>
        </div>
      </div>
      <div class="threeTopBox">
        <div class="left-border">
          <div class="box-title">检测单位名称：</div>
          <div class>{{ form.jiancdwmc }}</div>
        </div>
        <div class="right-border">
          <span>记录编号：</span>
          <span class="placeholder">{{ form.jilbh }}</span>
        </div>
      </div>
      <!-- .........................1111111111111111111111111111111......................................................... -->
      <div class="table-border">
        <table height="220px" class="top-table">
          <tbody>
          <tr>
            <td height="30" align="center" width="15%">
              <span style="width: 90px; display: inline-block">工程名称</span>
            </td>
            <td width="35%" class="text-center">
              <span>{{ form.gongcmc }}</span>
            </td>
            <td align="center" width="15%">
              <span style="width: 90px; display: inline-block">工程部位/用途</span>
            </td>
            <td width="35%" class="text-center">
              <span>{{ form.gongcbwyt }}</span>
            </td>
          </tr>
          <tr>
            <td height="50" align="center">样品信息</td>
            <td class="specimen-border" colspan="3">
              <span>样品名称：</span>
              <span :class="{ 'placeholder': !form.yangpmc }">{{ form.yangpmc }}</span>
              <span>；样品编号：</span>
              <span :class="{ 'placeholder-long': !form.yangpbh }">{{ form.yangpbh }}</span>
              <span>；样品数量：</span>
              <span :class="{ 'placeholder': !form.yangpsl }">{{ form.yangpsl }}</span>
              <span>；样品状态：</span>
              <span :class="{ 'placeholder': !form.yangpzt }">{{ form.yangpzt }}</span>
              <span>；来样时间：</span>
              <span :class="{ 'placeholder': !form.yangpsj }">{{ form.yangpsj }}</span>
            </td>
          </tr>

          <tr>
            <td height="25" align="center" width="15%">
              <span style="width: 90px; display: inline-block">试验检测日期</span>
            </td>
             <!-- <td width="35%" class="text-center">{{ form.shiyjcrq }}</td> -->                                            
 <td width="35%" class="text-center">
      <el-input v-model="form.shiyjcrq" />
</td>
            <td align="center" width="15%">
              <span style="width: 90px; display: inline-block">试验条件</span>
            </td>
            <td v-if="isPdf" width="35%">
              温度：
              <span style="display: inline-block; width: 10%;">{{ form.shiytjwd }}</span>
              ℃；湿度：
              <span style="display: inline-block; width: 10%;">{{ form.shiytjsd }}</span>%RH
            </td>
            <td v-else width="35%">
              温度：
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjwd" style="width: 15%"/>
              ℃；湿度：
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjsd" style="width: 15%"/>
              %RH
            </td>
          </tr>

          <tr>
            <td height="50" align="center" width="15%">
              <span style="width: 90px; display: inline-block">检测依据</span>
            </td>
            <td width="35%">
              <span v-if="isPdf">{{ form.jiancyj }}</span>
              <el-input v-else type="textarea" v-model="form.jiancyj" :rows="2" class="mark"
                        @dblclick.native="showBsJiancyjView" readonly/>
            </td>
            <td align="center" width="15%">
              <span style="width: 90px; display: inline-block">判定依据</span>
            </td>
            <td width="35%">
              <span v-if="isPdf">{{ form.pandyj }}</span>
              <el-input v-else type="textarea" v-model="form.pandyj" :rows="2"
                        @dblclick.native="showBsJudgeBaseView"
                        @focus="handleFocus('pandyj')" class="mark"/>
            </td>
          </tr>
          <tr class="bottom-border">
            <td height="50" align="center">
              <div>主要仪器设备</div>
              <div>名称及编号</div>
            </td>
            <td colspan="3">
              <span v-if="isPdf">{{ form.zhuyyqsbmcjbh }}</span>
              <el-input v-else type="textarea" :rows="2" v-model="form.zhuyyqsbmcjbh"
                        class="height100 width100 mark"
                        @dblclick.native="showBsInstrumentView" readonly></el-input>
            </td>
          </tr>
          </tbody>
        </table>
        <!-- .................................222222222221111111111111111111111............................................... -->
        <table height="80px" class="middle-table">
          <tbody>
          <tr>
            <td height="40" align="center" width="15%">取样地点</td>
            <td width="35%">
              <span>{{ this.form.quydd }}</span>
            </td>
            <td height="40" align="center" width="15%">代表数量</td>
            <td width="35%">
              <span>{{ this.form.daibsl }}</span>
            </td>
          </tr>
          <tr>
            <td align="center" height="40">进场日期</td>
            <td bgcolor="white">
              <span>{{ this.form.jincrq }}</span>
            </td>
            <td align="center" height="40">产地</td>
            <td bgcolor="white">
              <span>{{ this.form.cd }}</span>
            </td>
          </tr>
          </tbody>
        </table>
        <!-- .................................22222222222222222222222222222222............................................... -->
        <table height="516px" class="middle-table">
          <tbody>
          <tr trindex="0">
            <td rowspan="3" width="5%">
              <div
                style="width: 100%; writing-mode: vertical-rl; display: flex; justify-content: center; flex-direction: column;">
                松散堆积密度
              </div>
            </td>
            <td width="25%" colspan="2">
              <div>容量筒质量(kg)</div>
            </td>
            <td width="20%" colspan="2">
              <div>容量筒与试样总质量(kg)</div>
            </td>
            <td width="15%">
              <div>容量筒容积(L)</div>
            </td>
            <td width="15%">
              <div>堆积密度(kg/m³)</div>
            </td>
            <td width="20%">
              <div>平均值(kg/m³)</div>
            </td>
          </tr>
          <tr trindex="1" height="50">
            <td width="25%" colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                        v-model="form.songsrltzlItem1"
                        @change="computeSsDjMd(1)"
                        @keydown.native="handleKeyDown($event, 0, 0)"
                        @paste.native="handlePaste($event, 0, 0)"
                        :ref="'0_0'"/>
            </td>
            <td width="20%" colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                        v-model="form.songsrltsyzzlItem1"
                        @change="computeSsDjMd(1)"
                        @keydown.native="handleKeyDown($event, 0, 1)"
                        @paste.native="handlePaste($event, 0, 1)"
                        :ref="'0_1'"/>
            </td>
            <td width="15%">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                        v-model="form.songsrltrjItem1"
                        @change="computeSsDjMd(1)"
                        @keydown.native="handleKeyDown($event, 0, 2)"
                        @paste.native="handlePaste($event, 0, 2)"
                        :ref="'0_2'"/>
            </td>
            <td width="15%">
              <div>
                <div>{{ this.form.songsdjmdItem1 }}</div>
              </div>
            </td>
            <td width="20%" rowspan="2">
              <div>
                <div>{{ this.form.songsPjz }}</div>
              </div>
            </td>
          </tr>
          <tr trindex="2" height="50">
            <td width="25%" colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                        v-model="form.songsrltzlItem2"
                        @change="computeSsDjMd(2)"
                        @keydown.native="handleKeyDown($event, 1, 0)"
                        @paste.native="handlePaste($event, 1, 0)"
                        :ref="'1_0'"/>
            </td>
            <td width="20%" colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                        v-model="form.songsrltsyzzlItem2"
                        @change="computeSsDjMd(2)"
                        @keydown.native="handleKeyDown($event, 1, 1)"
                        @paste.native="handlePaste($event, 1, 1)"
                        :ref="'1_1'"/>
            </td>
            <td width="15%">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                        v-model="form.songsrltrjItem2"
                        @change="computeSsDjMd(2)"
                        @keydown.native="handleKeyDown($event, 1, 2)"
                        @paste.native="handlePaste($event, 1, 2)"
                        :ref="'1_2'"/>
            </td>
            <td width="15%">
              <div>
                <div>{{ this.form.songsdjmdItem2 }}</div>
              </div>
            </td>
          </tr>
          <tr trindex="3">
            <td rowspan="3" width="5%">
              <div
                style="width: 100%; writing-mode: vertical-rl; display: flex; justify-content: center; flex-direction: column;">
                振实堆积密度
              </div>
            </td>
            <td width="25%" colspan="2">
              <div>容量筒质量(kg)</div>
            </td>
            <td width="20%" colspan="2">
              <div>容量筒与试样总质量(kg)</div>
            </td>
            <td width="15%">
              <div>容量筒容积(L)</div>
            </td>
            <td width="15%">
              <div>堆积密度(kg/m³)</div>
            </td>
            <td width="20%">
              <div>平均值(kg/m³)</div>
            </td>
          </tr>
          <tr trindex="4" height="50">
            <td width="25%" colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                        v-model="form.zhensrltzlItem1"
                        @change="computeZsDjMd(1)"
                        @keydown.native="handleKeyDown($event, 2, 0)"
                        @paste.native="handlePaste($event, 2, 0)"
                        :ref="'2_0'"/>
            </td>
            <td width="20%" colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                        v-model="form.zhensrltsyzzlItem1"
                        @change="computeZsDjMd(1)"
                        @keydown.native="handleKeyDown($event, 2, 1)"
                        @paste.native="handlePaste($event, 2, 1)"
                        :ref="'2_1'"/>
            </td>
            <td width="15%">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                        v-model="form.zhensrltrjItem1"
                        @change="computeZsDjMd(1)"
                        @keydown.native="handleKeyDown($event, 2, 2)"
                        @paste.native="handlePaste($event, 2, 2)"
                        :ref="'2_2'"/>
            </td>
            <td width="15%">
              <div>{{ this.form.zhensdjmdItem1 }}</div>
            </td>
            <td width="20%" rowspan="2">
              <div>{{ this.form.zhensPjz }}</div>
            </td>
          </tr>
          <tr trindex="5" height="50">
            <td width="25%" colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                        v-model="form.zhensrltzlItem2"
                        @change="computeZsDjMd(2)"
                        @keydown.native="handleKeyDown($event, 3, 0)"
                        @paste.native="handlePaste($event, 3, 0)"
                        :ref="'3_0'"/>
            </td>
            <td width="20%" colspan="2">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                        v-model="form.zhensrltsyzzlItem2"
                        @change="computeZsDjMd(2)"
                        @keydown.native="handleKeyDown($event, 3, 1)"
                        @paste.native="handlePaste($event, 3, 1)"
                        :ref="'3_1'"/>
            </td>
            <td width="15%">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                        v-model="form.zhensrltrjItem2"
                        @change="computeZsDjMd(2)"
                        @keydown.native="handleKeyDown($event, 3, 2)"
                        @paste.native="handlePaste($event, 3, 2)"
                        :ref="'3_2'"/>
            </td>
            <td width="15%">
              <div>{{ this.form.zhensdjmdItem2 }}</div>
            </td>
          </tr>
          <tr trindex="6">
            <td rowspan="3" width="5%">
              <div
                style="width: 100%; writing-mode: vertical-rl; display: flex; justify-content: center; flex-direction: column;">
                表观密度
              </div>
            </td>
            <td width="12%">
              <div>集料水中质量(g)</div>
            </td>
            <td width="15%">
              <div>集料烘干质量(g)</div>
            </td>
            <td width="12%">
              <div>集料表干质量(g)</div>
            </td>
            <td width="10%">
              <div>水温(℃)</div>
            </td>
            <td width="15%">
              <div>水密度(g/cm³)</div>
            </td>
            <td width="15%">
              <div>表观密度(kg/m³)</div>
            </td>
            <td width="16%">
              <div>平均值(kg/m³)</div>
            </td>
          </tr>
          <tr trindex="7" height="50">
            <td width="10%">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                        v-model="form.jilszzlItem1"
                        @change="computeBgMd(1)"
                        @keydown.native="handleKeyDown($event, 4, 0)"
                        @paste.native="handlePaste($event, 4, 0)"
                        :ref="'4_0'"/>
            </td>
            <td width="15%">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                        v-model="form.jilhgzlItem1"
                        @change="jilhgzlChange(1)"
                        @keydown.native="handleKeyDown($event, 4, 1)"
                        @paste.native="handlePaste($event, 4, 1)"
                        :ref="'4_1'"/>
            </td>
            <td width="10%">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                        v-model="form.jilbgzlItem1"
                        @change="computeXsl(1)"
                        @keydown.native="handleKeyDown($event, 4, 2)"
                        @paste.native="handlePaste($event, 4, 2)"
                        :ref="'4_2'"/>
            </td>
            <td width="10%">
              <!-- <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.shuiwItem1" /> -->
              <el-select v-model="form.shuiwItem1" class="hide-icon height100" placeholder
                         @change="shuiwenChange(1)">
                <el-option v-for="(item, index) in shuiwenList" :key="index" :label="item.temp"
                           :value="item.temp"></el-option>
              </el-select>
            </td>
            <td width="15%">
              <!-- <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.shuimdItem1" @change="computeBgMd(1)" /> -->
              {{ form.shuimdItem1 }}
            </td>
            <td width="15%">
              <div>{{ this.form.biaogmdItem1 }}</div>
            </td>
            <td width="20%" rowspan="2">
              <div>{{ this.form.biaogmdPjz }}</div>
            </td>
          </tr>
          <tr trindex="8" height="50">
            <td width="10%">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                        v-model="form.jilszzlItem2"
                        @change="computeBgMd(2)"
                        @keydown.native="handleKeyDown($event, 5, 0)"
                        @paste.native="handlePaste($event, 5, 0)"
                        :ref="'5_0'"/>
            </td>
            <td width="15%">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                        v-model="form.jilhgzlItem2"
                        @change="jilhgzlChange(2)"
                        @keydown.native="handleKeyDown($event, 5, 1)"
                        @paste.native="handlePaste($event, 5, 1)"
                        :ref="'5_1'"/>
            </td>
            <td width="10%">
              <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                        v-model="form.jilbgzlItem2"
                        @change="computeXsl(2)"
                        @keydown.native="handleKeyDown($event, 5, 2)"
                        @paste.native="handlePaste($event, 5, 2)"
                        :ref="'5_2'"/>
            </td>
            <td width="10%">
              <!-- <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.shuiwItem2" /> -->
              <el-select v-model="form.shuiwItem2" class="hide-icon height100" placeholder
                         @change="shuiwenChange(2)">
                <el-option v-for="(item, index) in shuiwenList" :key="index" :label="item.temp"
                           :value="item.temp"></el-option>
              </el-select>
            </td>
            <td width="15%">
              {{ form.shuimdItem2 }}
              <!-- <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.shuimdItem2" @change="computeBgMd(2)" /> -->
            </td>
            <td width="15%">
              <div>{{ this.form.biaogmdItem2 }}</div>
            </td>
          </tr>
          <tr trindex="9">
            <td rowspan="2" width="5%">
              <div
                style="width: 100%; writing-mode: vertical-rl; display: flex; justify-content: center; flex-direction: column;">
                吸水率
              </div>
            </td>
            <td width="65%" colspan="5">
              <div>单值(%)</div>
            </td>
            <td width="30%" colspan="2">
              <div>平均值(%)</div>
            </td>
          </tr>
          <tr trindex="10" height="50">
            <td width="65%" colspan="2">
              <div>{{ this.form.xisldzItem1 }}</div>
            </td>
            <td width="65%" colspan="3">
              <div>{{ this.form.xisldzItem2 }}</div>
            </td>
            <td width="30%" colspan="2">
              <div>{{ this.form.xislPjz }}</div>
            </td>
          </tr>
          <tr trindex="10">
            <td width="100%" colspan="8">
              <div>
                <div style="display: inline-block;height: 100%;">空隙率 = ( 1 - 堆积密度 / 表观密度 ) *
                  100 =
                </div>
                <div style="display: inline-block;margin-left: 50px;">{{ this.form.kongxl }} %</div>
              </div>
            </td>
          </tr>
          </tbody>
        </table>
        <!-- .....................................................33333333333333333................................................... -->
        <table height="80px" class="bottom-table">
          <tr>
            <td>
              <span v-if="isPdf" class="textarea-span">{{ form.fujsm }}</span>
              <el-input v-else type="textarea" :rows="2" v-model="form.fujsm"
                        @focus="handleFocus('fujsm')"/>
            </td>
          </tr>
        </table>
      </div>
      <!-- .................................44444444444............................................. -->
      <table height="22px" class="transparent">
        <tbody>
        <tr>
          <td width="10%" align="right">检测：</td>
          <td width="15%" align="left">
            <!-- {{this.form.jiancr}} -->
          </td>
          <td width="10%" align="right">记录：</td>
          <td width="15%" align="left">
            <!-- {{this.form.jilr}} -->
          </td>
          <td width="10%" align="right">复核：</td>
          <td align="left" width="15%">
            <!-- {{this.form.fuhr}} -->
          </td>
          <td width="10%">日期：</td>
          <td align="left" width="15%">
            <div style="display: inline-block; margin-right: 30px;">年</div>
            <div style="display: inline-block; margin-right: 30px;">月</div>
            <div style="display: inline-block;">日</div>
          </td>
        </tr>
        </tbody>
      </table>
    </div>
    <bs-instrument-view ref="bsInstrumentViewRef" @select="selectInstrument"></bs-instrument-view>
    <bs-jiancyj-view ref="bsJiancyjViewRef" @select="selectJiancyj" :syType="syType"></bs-jiancyj-view>
    <bs-judge-base-view ref="bsJudgeBaseViewRef" @select="selectJudge" :syType="syType"></bs-judge-base-view>
  </div>
</template>

<script>
import {handleFocus, emptyConvert, uniqueStr, handleKeyDown, handlePaste} from "@/views/reportForms/utils";
import {getCjlmdxslwlfhntyjlbBsInfo} from "@/api/report_jl/cjl";
import {listBySyTypeId} from "@/api/sycs/dataBase";
import BsInstrumentView from "@/views/dept/bsInstrument/BsInstrumentView";
import BsJiancyjView from "@/views/sycs/bsJiancyj/BsJiancyjView";
import BsJudgeBaseView from "@/views/sycs/bsJudgeBase/BsJudgeBaseView.vue";

import decimal from "@/utils/big-decimal";
import Bus from "@/utils/bus";

export default {
  name: "cjlmdxslwlfhntyjlb",
  components: {
    BsInstrumentView,
    BsJiancyjView,
    BsJudgeBaseView
  },
  props: {
    excelId: {
      type: [String, Number],
      default: () => ""
    },
    syType: {
      type: [String, Number],
      default: () => ""
    },
    page: {
      type: Number,
      default: () => 0
    },
    isPdf: {
      type: Boolean,
      default: () => false
    },
    printEmpty: {
      type: Boolean,
      default: () => false
    }
  },
  data() {
    return {
      form: {
        detailList: [],
        baobbhList: []
      },
      backBgz: {},
      show: false,
      showQyxx: true,
      shuiwenList: []
    };
  },
  created() {
    this.init();
    this.getShuiwenList();
  },
  watch: {
    isPdf(newVal, oldVal) {
      this.form = {...emptyConvert(this.form, newVal)};
    }
  },
  methods: {
    // 根据报表id获取当前报表信息
    init() {
      this.show = false;
      getCjlmdxslwlfhntyjlbBsInfo(this.excelId || this.$defaultExcelId).then((response) => {
        this.form = response.data;
        this.setInitialValue();
        this.show = true;
      });
    },
    getShuiwenList() {
      listBySyTypeId({syYjId: "281757153833"}).then((response) => {
        const data = response.data;
        this.shuiwenList = data.page.records;
      });
    },
    // 设置初始值
    setInitialValue() {
      if (this.form) {
        this.form.baobmc = this.form.baobmc || "粗集料密度试验检测记录表（网篮法）";
        this.form.baobbh = this.form.baobbh || "JGLQ02002a";
        this.$set(this.form, "baobbhList", []);
        this.form.baobbhList = ["JGLQ02002a"];
      }
      if (!this.form.fujsm) {
        this.form.fujsm = "附加声明：";
      }
    },
    // 显示仪器列表
    showBsInstrumentView() {
      this.$refs.bsInstrumentViewRef.init(this.form.shebIds);
    },
    // 仪器选择
    selectInstrument(info) {
      this.form.zhuyyqsbmcjbh = info.label;
      this.form.shebIds = info.ids;
      Bus.$emit("setCjlBgZhuyyqsbmcjbh", {zhuyyqsbmcjbh: this.form.zhuyyqsbmcjbh, shebIds: this.form.shebIds});
    },
    // 显示检测依据列表
    showBsJiancyjView() {
      this.$refs.bsJiancyjViewRef.init(this.form.jiancyjIds);
    },
    // 检测依据选择
    selectJiancyj(info) {
      this.form.jiancyj = info.label;
      this.form.jiancyjIds = info.ids;
      Bus.$emit("setCjlBgJiancyj", {jiancyj: this.form.jiancyj, jiancyjIds: this.form.jiancyjIds});
    },
    // 显示判定依据列表
    showBsJudgeBaseView() {
      this.$refs.bsJudgeBaseViewRef.init(this.form.pandyjIds);
    },
    // 判断依据选择
    selectJudge(info) {
       this.form.pandyjIds = info.ids;
      this.form.pandyj = info.label;
    },
    // 返回报告引入值
    backBgzFun() {
      // this.$emit("backBgzFun", this.backBgz);
      Bus.$emit("setCjlBgJiancjg", [
        {key: 23, value: this.form.songsPjz},
        {key: 24, value: this.form.zhensPjz},
        {key: 22, value: this.form.biaogmdPjz},
        {key: 25, value: this.form.xislPjz},
        {key: 26, value: this.form.kongxl}
      ]);
    },
    submitForm() {
      return this.form;
    },
    handleFocus(event) {
      handleFocus(event, this.page, this.form[event]);
    },
    // 水温改变
    shuiwenChange(index) {
      const info = this.shuiwenList.find((item) => item.temp == this.form["shuiwItem" + index]);
      if (!info) {
        return;
      }
      this.form["shuimdItem" + index] = info.density;
      this.computeBgMd(index);
    },
    // 松散堆积密度
    computeSsDjMd(index) {
      songsrltrjItem;
      const songsrltsyzzlItem = this.form["songsrltsyzzlItem" + index];
      const songsrltzlItem = this.form["songsrltzlItem" + index];
      const songsrltrjItem = this.form["songsrltrjItem" + index];
      const a = decimal.subtract(songsrltsyzzlItem || 0, songsrltzlItem || 0);
      if (songsrltrjItem && songsrltrjItem != 0) {
        const b = decimal.divide(a, songsrltrjItem);
        // const c = decimal.multiply(b, 0.001);
        this.form["songsdjmdItem" + index] = b;
      } else {
        this.form["songsdjmdItem" + index] = null;
      }
      // 平均值
      if (this.form.songsdjmdItem1 && this.form.songsdjmdItem2) {
        const d = decimal.add(this.form.songsdjmdItem1 || 0, this.form.songsdjmdItem2 || 0);
        const e = decimal.divide(d, 2, 1);
        this.form.songsPjz = e;
      } else {
        this.form.songsPjz = null;
      }
      // this.$set(this.backBgz, "songsPjz", this.form.songsPjz);
      this.backBgzFun();
    },
    // 振实堆积密度
    computeZsDjMd(index) {
      const zhensrltsyzzlItem = this.form["zhensrltsyzzlItem" + index];
      const zhensrltzlItem = this.form["zhensrltzlItem" + index];
      const zhensrltrjItem = this.form["zhensrltrjItem" + index];
      const a = decimal.subtract(zhensrltsyzzlItem || 0, zhensrltzlItem || 0);
      if (zhensrltrjItem && zhensrltrjItem != 0) {
        const b = decimal.divide(a, zhensrltrjItem);
        // const c = decimal.multiply(b, 0.001);
        this.form["zhensdjmdItem" + index] = b;
      } else {
        this.form["zhensdjmdItem" + index] = null;
      }
      // 平均值
      if (this.form.zhensdjmdItem1 && this.form.zhensdjmdItem2) {
        const d = decimal.add(this.form.zhensdjmdItem1 || 0, this.form.zhensdjmdItem2 || 0);
        const e = decimal.divide(d, 2);
        this.form.zhensPjz = e;
      } else {
        this.form.zhensPjz = null;
      }
      // this.$set(this.backBgz, "zhensPjz", this.form.zhensPjz);
      // 计算空隙率
      this.computeKxl();
    },
    // 两个都算
    jilhgzlChange(index) {
      this.computeBgMd(index);
      this.computeXsl(index);
    },
    // 表观密度
    computeBgMd(index) {
      // const shuimdItem = this.form["shuimdItem" + index]; // 水密度E
      // const jilhgzlItem = this.form["jilhgzlItem" + index]; // 集料烘干质量C
      // const jilszzlItem = this.form["jilszzlItem" + index]; // 集料水中质量A

      // const a = decimal.multiply(shuimdItem || 0, jilhgzlItem || 0, 6);
      // const b = decimal.subtract(jilhgzlItem || 0, jilszzlItem || 0, 6);
      // if (b != 0 && this.form['shuimdItem' + index]) {
      //   const c = decimal.divide(a, b, 6);
      //   const m = decimal.multiply(c, 1000, 6);
      //   const n = decimal.multiply(m, this.form['shuimdItem' + index], 0);
      //   this.form["biaogmdItem" + index] = n;
      // } else {
      //   this.form["biaogmdItem" + index] = null;
      // }
      const E = this.form["shuimdItem" + index]; // 水密度E
      const C = this.form["jilhgzlItem" + index]; // 集料烘干质量C
      const A = this.form["jilszzlItem" + index]; // 集料水中质量A
      if (C && C - A && (C - A) !== 0) {
        this.form["biaogmdItem" + index] = decimal.multiply((C / (C - A)) * E * 1000, 1, 0);
      }else {
        this.form["biaogmdItem" + index] = null;
      }
      // 平均值
      if (this.form.biaogmdItem1 && this.form.biaogmdItem2) {
        const d = decimal.add(this.form.biaogmdItem1 || 0, this.form.biaogmdItem2 || 0);
        const e = decimal.divide(d, 2, 0);
        this.form.biaogmdPjz = e;
      } else {
        this.form.biaogmdPjz = null;
      }
      // this.$set(this.backBgz, "biaogmdPjz", this.form.biaogmdPjz);
      this.computeKxl();
    },
    // 吸水率
    computeXsl(index) {
      const jilbgzlItem = this.form["jilbgzlItem" + index];
      const jilhgzlItem = this.form["jilhgzlItem" + index];
      const a = decimal.subtract(jilbgzlItem || 0, jilhgzlItem || 0);
      if (jilhgzlItem && jilhgzlItem != 0) {
        const b = decimal.multiply(a, 100);
        const e = decimal.divide(b, jilhgzlItem);
        this.form["xisldzItem" + index] = e;
      } else {
        this.form["xisldzItem" + index] = null;
      }
      // 平均值
      if (this.form.xisldzItem1 && this.form.xisldzItem2) {
        const c = decimal.add(this.form.xisldzItem1 || 0, this.form.xisldzItem2 || 0);
        const d = decimal.divide(c, 2);
        this.form.xislPjz = d;
      } else {
        this.form.xislPjz = null;
      }
      // this.$set(this.backBgz, "xislPjz", this.form.xislPjz);
      this.backBgzFun();
    },
    // 空隙率: 有松散密度用松散密度,无松散密度用振实密度
    computeKxl() {
      if (this.form.biaogmdPjz && this.form.biaogmdPjz != 0) {
        if (this.form.songsPjz) {
          const a = decimal.divide(this.form.songsPjz || 0, this.form.biaogmdPjz);
          const b = decimal.subtract(1, a);
          const c = decimal.multiply(b, 100);
          this.form.kongxl = c;
        } else if (this.form.zhensPjz) {
          const a = decimal.divide(this.form.zhensPjz || 0, this.form.biaogmdPjz);
          const b = decimal.subtract(1, a);
          const c = decimal.multiply(b, 100);
          this.form.kongxl = c;
        } else {
          this.form.kongxl = null;
        }
      } else {
        this.form.kongxl = null;
      }
      // this.$set(this.backBgz, "kongxl", this.form.kongxl);
      this.backBgzFun();
    },
    handleKeyDown(event, rowIndex, colIndex) {
      const maxArr = [2, 2, 2, 2, 2, 2]; // 每一行最多有多少可聚焦输入框（从0开始）
      const ref = handleKeyDown(event, rowIndex, colIndex, maxArr);
      if (this.$refs[ref]) {
        this.$refs[ref].focus();
      }
    },
    // 粘贴赋值方法
    handlePaste(event, rowIndex, colIndex) {
      const nameAllArr = [
        ["songsrltzlItem1", "songsrltsyzzlItem1", "songsrltrjItem1"],
        ["songsrltzlItem2", "songsrltsyzzlItem2", "songsrltrjItem2"],

        ["zhensrltzlItem1", "zhensrltsyzzlItem1", "zhensrltrjItem1"],
        ["zhensrltzlItem2", "zhensrltsyzzlItem2", "zhensrltrjItem2"],

        ["jilszzlItem1", "jilhgzlItem1", "jilbgzlItem1"],
        ["jilszzlItem2", "jilhgzlItem2", "jilbgzlItem2"],

      ];
      const subscriptArr = [
        [0, 1, 2],
        [0, 1, 2],

        [0, 1, 2],
        [0, 1, 2],

        [0, 1, 2],
        [0, 1, 2],
      ];

      const methodsAllArr = [
        ["computeSsDjMd", "computeSsDjMd", "computeSsDjMd"],
        ["computeSsDjMd", "computeSsDjMd", "computeSsDjMd"],

        ["computeZsDjMd", "computeZsDjMd", "computeZsDjMd"],
        ["computeZsDjMd", "computeZsDjMd", "computeZsDjMd"],

        ["computeBgMd", "jilhgzlChange", "computeXsl"],
        ["computeBgMd", "jilhgzlChange", "computeXsl"],
      ];
      const parameterArr = [
        [1, 1, 1],
        [2, 2, 2],

        [1, 1, 1],
        [2, 2, 2],

        [1, 1, 1],
        [2, 2, 2],
      ];
      const data = handlePaste(event, rowIndex, colIndex, nameAllArr, methodsAllArr, parameterArr, subscriptArr);
      const {cols, nameSetArr, methodsSetArr, parameterSetArr, subscriptSetArr} = data;
      for (let a = 0; a < nameSetArr.length; a++) {
        for (let b = 0; b < nameSetArr[a].length; b++) {
          this.form[nameSetArr[a][b]] = cols[a][b];
        }
      }
      for (let a = 0; a < methodsSetArr.length; a++) {
        for (let b = 0; b < methodsSetArr[a].length; b++) {
          // if (methodsSetArr[a][b] == "calculateShitzl") {
          // console.log(methodsSetArr[a][b], subscriptArr[a][b]);

          this.setCalculate(methodsSetArr[a][b], parameterSetArr[a][b]);
          // } else {
          // this.setCalculate(methodsSetArr[a][b], parameterSetArr[a][b][0], parameterSetArr[a][b][1]);
          // }
        }
      }
    },


    // 计算方法调用
    setCalculate(name, a, b, c, d, e) {
      this[name](a, b, c, d, e);
    }
  }
};
</script>

<style scoped lang="scss"></style>
